<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="Database.Document" %>
<%@ page import="java.util.Vector" %>

<%@ include file="/header" %>

<%     
    Vector<Document> list = null;
    int i = 0;
    
    try
    {
        list = (Vector<Document>)request.getAttribute("list");
    }
    catch(Exception e)
    {
        ///if the file list is null, redirect to the proper  page...
        response.sendRedirect(siteRoot+"/query");
    }
    
    if( list == null
        || request.getParameter("query") == null
        || request.getParameter("n") == null)
    {
        response.sendRedirect(siteRoot+"/query");
    }
%>

    <div id="queryForm">
        <p>Enter some keywords to perform a simple query.</p>
        <form action="<%=siteRoot%>/query" method="get">
            <input type="text" name="query" value="<%=request.getParameter("query")%>" alt="Enter your query" title="Enter your query" />
            <select name="n" alt="Show the first n documents" title="Show the first n documents">
                <option value="1" <% if(request.getParameter("n").equals("1")) out.write("selected");%> /> 1
                <option value="2" <% if(request.getParameter("n").equals("2")) out.write("selected");%> /> 2
                <option value="3" <% if(request.getParameter("n").equals("3")) out.write("selected");%> /> 3
                <option value="4" <% if(request.getParameter("n").equals("4")) out.write("selected");%> /> 4
                <option value="5" <% if(request.getParameter("n").equals("5")) out.write("selected");%> /> 5
                <option value="6" <% if(request.getParameter("n").equals("6")) out.write("selected");%> /> 6
                <option value="7" <% if(request.getParameter("n").equals("7")) out.write("selected");%> /> 7
                <option value="8" <% if(request.getParameter("n").equals("8")) out.write("selected");%> /> 8
                <option value="9" <% if(request.getParameter("n").equals("9")) out.write("selected");%> /> 9
                <option value="10" <% if(request.getParameter("n").equals("10")) out.write("selected");%> /> 10
            </select>
            <input type="image" id="querySubmitIcon" src="<%=siteRoot%>/query/query.png" alt="Find relevant documents" title="Find relevant documents" />
        </form>
        Or <a href="<%=siteRoot%>/train">input a new training query</a>.
    </div>
    
    <h2>Results</h2>
    
    <div id="resultQuery">
        <%           
            for(Document doc : list)
            {
        %>
        <h3>
            <%=++i%>. <font size="20"><a href="<%=doc.getUrl()%>" alt=""><%=doc.getTitle()%></a></font>
            <font size="10">
                <br /><%=doc.getSummary()%>
                <br /><%=doc.getSearchEngine()%>
                <br /><font color="green"><%=doc.getUrl()%></font>
            </font>
        </h3>
        <%
            }
        %>
    </div>
    
<%@ include file="/footer" %>
